package com.example.visitedsys.converter;

import com.example.visitedsys.informationGet.PermissionNodeVO;
import com.example.visitedsys.informationGet.PermissionVO;
import com.example.visitedsys.pojo.Permission;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author  SongPeng
 * @date  2021/11/04 14:22
 * @version 1.0
 */

public class MenuConverter {
    /**
     * 转成PermissionNodeVO(只包含菜单)List
     * @param permissions
     * @return
     */
    public static List<PermissionNodeVO> converterToMenuNodeVO(List<Permission> permissions){
        //先过滤出用户的菜单
        List<PermissionNodeVO> permissionNodeVOS=new ArrayList<>();
        if(!CollectionUtils.isEmpty(permissions)){
            for (Permission permission : permissions) {
                if(permission.getPermissionType()==0){
                    PermissionNodeVO permissionNodeVO = new PermissionNodeVO();
                    permissionNodeVO.setDisabled(permission.getPermissionStatus()==0);
                    BeanUtils.copyProperties(permission,permissionNodeVO);
                    permissionNodeVOS.add(permissionNodeVO);
                }
            }
        }
        return permissionNodeVOS;
    }


    /**
     * 转成PermissionNodeVO(菜单和按钮）
     * @param permissions
     * @return
     */
    public static List<PermissionNodeVO> converterToALLMenuNodeVO(List<Permission> permissions){
        //先过滤出用户的菜单
        List<PermissionNodeVO> menuNodeVOS=new ArrayList<>();
        if(!CollectionUtils.isEmpty(permissions)){
            for (Permission permission : permissions) {
                PermissionNodeVO menuNodeVO = new PermissionNodeVO();
                BeanUtils.copyProperties(permission,menuNodeVO);
                menuNodeVO.setDisabled(permission.getPermissionStatus()==0);
                menuNodeVOS.add(menuNodeVO);
            }
        }
        return menuNodeVOS;
    }
    /**
     * 转成PermissionVO(菜单和按钮）
     * @param
     * @return
     */
    public static PermissionVO converterToMenuVO(Permission permission){
        PermissionVO permissionVO = new PermissionVO();
        if(permission!=null){
            BeanUtils.copyProperties(permission,permissionVO);
            permissionVO.setDisabled(permission.getPermissionStatus()==0);
        }
        return permissionVO;
    }

}
